这是Abaqus内嵌的一个插件实例,在窗口中输入零件名、零件宽度、零件高度以及圆孔半径之后,点击“OK”,会在Abaqus中自动生成带孔板的几何模型。 该插件共由四个文件组成:
- 注册文件createPlateWithhole_plugin.py
- 图形界面文件createPlateWithholeDB.py
- 内核执行文件createPlateModul.py
- 图标文件planewithhole
1. 注册文件createPlateWithhole_plugin.py# -* - coding:UTF-8 -*-#当Python代码中有中文时,在开头加-* - coding:UTF-8 -*-from abaqusGui import *from abaqusConstants import ALLimport osutils, os############################################################################ Class definition###########################################################################class createPlateWithhole_plugin(AFXForm): #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def __init__(self, owner): # Construct the base class. # AFXForm.__init__(self, owner) self.radioButtonGroups = {} self.cmd = AFXGuiCommand(mode=self, method='createPlateFunction', objectName='createPlateModul', registerQuery=False) pickedDefault = '' self.partnameKw = AFXStringKeyword(self.cmd, 'partname', True, 'part-1') self.widthKw = AFXFloatKeyword(self.cmd, 'width', True,100) self.heightKw = AFXFloatKeyword(self.cmd, 'height', True,100) self.radiusKw = AFXFloatKeyword(self.cmd, 'radius', True,5) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def getFirstDialog(self): import createPlateWithholeDB return createPlateWithholeDB.createPlateWithholeDB(self) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def doCustomChecks(self): # Try to set the appropriate radio button on. If the user did # not specify any buttons to be on, do nothing. # for kw1,kw2,d in self.radioButtonGroups.values(): try: value = d[ kw1.getValue() ] kw2.setValue(value) except: pass return True #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def okToCancel(self): # No need to close the dialog when a file operation (such # as New or Open) or model change is executed. # return False#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# Register the plug-in#thisPath = os.path.abspath(__file__)thisDir = os.path.dirname(thisPath)toolset = getAFXApp().getAFXMainWindow().getPluginToolset()toolset.registerGuiMenuButton( buttonText='创建带孔板', object=createPlateWithhole_plugin(toolset), messageId=AFXMode.ID_ACTIVATE, icon=None, kernelInitString='import createPlateModul', applicableModules=ALL, version='N/A', author='N/A', description='N/A', helpUrl='N/A')
2. 图形界面文件createPlateWithholeDB.py# -* - coding:UTF-8 -*-from abaqusConstants import *from abaqusGui import *from kernelAccess import mdb, sessionimport osthisPath = os.path.abspath(__file__)thisDir = os.path.dirname(thisPath)######################################################################## Class definition#######################################################################class createPlateWithholeDB(AFXDataDialog): ID_Mybutton = AFXDataDialog.ID_LAST #分配ID def __init__(self, form): AFXDataDialog.__init__(self, form, '带孔板参数化建模程序', self.OK|self.CANCEL, DIALOG_ACTIONS_SEPARATOR) okBtn = self.getActionButton(self.ID_CLICKED_OK) okBtn.setText('OK') GroupBox_1 = FXGroupBox(p=self, text='参数', opts=FRAME_GROOVE)#创建控件组 AFXTextField(p=GroupBox_1, ncols=12, labelText='零件名 :', tgt=form.partnameKw, sel=0)#创建文本框 AFXTextField(p=GroupBox_1, ncols=12, labelText='宽度(w):', tgt=form.widthKw, sel=0) AFXTextField(p=GroupBox_1, ncols=12, labelText='高度(h):', tgt=form.heightKw, sel=0) AFXTextField(p=GroupBox_1, ncols=12, labelText='半径(r):', tgt=form.radiusKw, sel=0) GroupBox_3 = FXGroupBox(p=self, text='示意图', opts=FRAME_GROOVE) fileName = os.path.join(thisDir, r'planewithhole.png') icon = afxCreatePNGIcon(fileName) FXLabel(p=GroupBox_3, text='', ic=icon) FXMAPFUNC(self, SEL_COMMAND, self.ID_Mybutton, createPlateWithholeDB.onCmdMybutton) FXButton(p=self, text='打印', ic=None, tgt=self, sel=self.ID_Mybutton, opts=BUTTON_NORMAL, x=0, y=0, w=0, h=0, pl=0) def onCmdMybutton(self, sender, sel, ptr): if SELID(sel) == self.ID_Mybutton: #使用SELID函数获取消息ID print 'Button 1 was pressed.' #在DOS界面下输出提示信息 mw = getAFXApp().getAFXMainWindow() mw.writeToMessageArea('Button 1 was pressed.' ) #在abaqus/CAE主窗口下方的提示区显示提示信息 return 1
3. 内核执行文件createPlateModul.py# -* - coding:UTF-8 -*-from abaqus import *from abaqusConstants import *def createPlateFunction(partname, width, height, radius): mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=200.0) mdb.models['Model-1'].sketches['__profile__'].rectangle(point1=(0.0, 0.0), point2=(width, height)) mdb.models['Model-1'].sketches['__profile__'].CircleByCenterPerimeter(center=( width/2, height/2), point1=(width/2 radius, height/2)) mdb.models['Model-1'].Part(dimensionality=THREE_D, name=partname, type= DEFORMABLE_BODY) mdb.models['Model-1'].parts[partname].BaseShell(sketch= mdb.models['Model-1'].sketches['__profile__']) p = mdb.models['Model-1'].parts[partname] session.viewports['Viewport: 1'].setValues(displayedObject=p) del mdb.models['Model-1'].sketches['__profile__'] #几何创建完成 mdb.models['Model-1'].Material(name='AL') mdb.models['Model-1'].materials['AL'].Elastic(table=((70000.0, 0.3), )) mdb.models['Model-1'].HomogeneousShellSection(name='al', preIntegrate=OFF, material='AL', thicknessType=UNIFORM, thickness=1.0, thicknessField='', idealization=NO_IDEALIZATION, poissonDefinition=DEFAULT, thicknessModulus=None, temperature=GRADIENT, useDensity=OFF, integrationRule=SIMPSON, numIntPts=5) f = p.faces faces = f.getSequenceFromMask(mask=('[#1 ]', ), ) region = p.Set(faces=faces, name='Set-2') p.SectionAssignment(region=region, sectionName='al', offset=0.0, offsetType=MIDDLE_SURFACE, offsetField='', thicknessAssignment=FROM_SECTION) #建立材料并赋予属性 session.viewports['Viewport: 1'].partDisplay.setValues(mesh=ON) session.viewports['Viewport: 1'].partDisplay.meshOptions.setValues( meshTechnique=ON) session.viewports['Viewport: 1'].partDisplay.geometryOptions.setValues( referenceRepresentation=OFF) #切换到mesh模块 p = mdb.models['Model-1'].parts[partname] p.seedPart(size=4.0, deviationFactor=0.1, minSizeFactor=0.1) f = p.faces pickedRegions = f.findAt(((width/2, 0.0, 0.0), )) p.setMeshControls(regions=pickedRegions, elemShape=QUAD,algorithm=MEDIAL_AXIS) #设定网格划分格式 p.generateMesh() #网格划分 a = mdb.models['Model-1'].rootAssembly session.viewports['Viewport: 1'].setValues(displayedObject=a) session.viewports['Viewport: 1'].assemblyDisplay.setValues( optimizationTasks=OFF, geometricRestrictions=OFF, stopConditions=OFF) #切换到装配模块 a = mdb.models['Model-1'].rootAssembly a.DatumCsysByDefault(CARTESIAN) p = mdb.models['Model-1'].parts[partname] a.Instance(name=partname '-1', part=p, dependent=ON) #创建装配实例 mdb.models['Model-1'].StaticStep(name='Step-1', previous='Initial', nlgeom=ON) session.viewports['Viewport: 1'].assemblyDisplay.setValues(step='Step-1') #创建分析步 session.viewports['Viewport: 1'].view.setValues(nearPlane=335.564, farPlane=385.546, width=212.48, height=142.547, viewOffsetX=13.3712, viewOffsetY=-7.13345) a = mdb.models['Model-1'].rootAssembly e1 = a.instances[partname '-1'].edges edges1 = e1.findAt(((0.0, height/2, 0.0), )) region = a.Set(edges=edges1, name='Set-1') mdb.models['Model-1'].DisplacementBC(name='BC-1', createStepName='Step-1', region=region, u1=0.0, u2=0.0, u3=0.0, ur1=0.0, ur2=0.0, ur3=0.0, amplitude=UNSET, fixed=OFF, distributionType=UNIFORM, fieldName='', localCsys=None) #施加边界条件 edges1 = e1.findAt(((width, height/2, 0.0), )) region = a.Set(edges=edges1, name='Set-2') mdb.models['Model-1'].DisplacementBC(name='BC-2', createStepName='Step-1', region=region, u1=2.0, u2=UNSET, u3=UNSET, ur1=UNSET, ur2=UNSET, ur3=UNSET, amplitude=UNSET, fixed=OFF, distributionType=UNIFORM, fieldName='', localCsys=None) #施加位移载荷 mdb.Job(name='Job-hole', model='Model-1', description='', type=ANALYSIS, atTime=None, waitMinutes=0, waitHours=0, queue=None, memory=50, memoryUnits=PERCENTAGE, getMemoryFromAnalysis=True, explicitPrecision=SINGLE, nodalOutputPrecision=SINGLE, echoPrint=OFF, modelPrint=OFF, contactPrint=OFF, historyPrint=OFF, userSubroutine='', scratch='', multiprocessingMode=DEFAULT, numCpus=1, numGPUs=0) #创建job
评论